using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using Mani.Security;

/// <summary>
/// Base class that all pages of web site derives from
/// this is usefull for setting themes, user language, checking authorization and other things
/// </summary>
public class BasePage : System.Web.UI.Page
{
    RuleProvider ruleProvider = new RuleProvider();

    private string _actionName;

    public virtual string ActionName {
        get { return _actionName; }
    }


    protected override void OnPreInit( EventArgs e ) {
        if (!IsActionPermited( this.ActionName )) {
            if (String.IsNullOrEmpty( User.Identity.Name ))
                Response.Redirect( "~/login.aspx", false );
            else
                Response.Redirect( "~/AccessDenied.aspx", false );
        }

        Page.Theme = MyTheme.Value;
        Page.Culture = MyCulture.Value;
        Page.UICulture = MyCulture.Value;

        if (!String.IsNullOrEmpty( User.Identity.Name )) {
            MembershipUser user = Membership.GetUser( User.Identity.Name, true );
            Membership.UpdateUser( user );
        }
    }

    public bool IsActionPermited(string actionName) {
        return ruleProvider.IsActionPermited( actionName, User.Identity.Name );
    }
}
